package com.alone.embedded.lucene.quickstart.spring;

import com.alone.embedded.lucene.exception.EmbeddedLuceneException;
import com.alone.embedded.lucene.quickstart.Article;
import com.alone.embedded.lucene.repository.ElRepository;
import com.alone.embedded.lucene.spring.annotation.ElTransactional;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author Alone
 */
@Service
@RequiredArgsConstructor
@ElTransactional
public class ArticleService {

    @Getter
    private final ElRepository<Article> repository;

    @ElTransactional
    public void insert() {
        repository.insert(Article.DATA);
        // 加事务后，发生异常自动回滚
        throw EmbeddedLuceneException.of("some error happen here!");
    }

}
